package A一周刷爆LeetCode.A基础班.H前缀树和贪心算法;

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * @author wei.zhao
 * @description: 安排最多场会议
 * @date 2022年03月24日 17:29
 */
public class Code02_BestArrange {

    public static class Program {
        public int start;
        public int end;

        public Program(int start, int end) {
            this.start = start;
            this.end = end;
        }
    }

    public static int bestArrange(Program[] programs, int start) {
        PriorityQueue<Program> queue = new PriorityQueue<>(Comparator.comparing(e -> e.end));
        for (Program program : programs) {
            queue.add(program);
        }
        int result = 0;
        while (!queue.isEmpty()) {
            Program program = queue.poll();
            if (program.start >= start) {
                result++;
                start = program.end;
            }
        }
        return result;
    }

}
